<template>
  <div style="margin-top: 20px; padding: 20px 300px 10px 60px">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="分类名称">
        <el-input v-model="params.categoryName"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="edit">修改</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getCategory } from "@/api/category";
import { editCategory } from "@/api/category";

export default {
  data() {
    return {
      form: {
        categoryName: "",
      },
      params: {
        categoryName: "",
        categoryId: this.$route.query.categoryId,
      },
    };
  },
  methods: {
    edit() {
      editCategory(this.params).then((res) => {
        this.$message.success("修改成功");
        this.$router.push("/category/list");
      });
    },
    show() {
      getCategory(this.$route.query.categoryId)
        .then((res) => {
          // console.log(res);
          this.params.categoryName = res.data;
        })
        .catch((reason) => {});
    },
    onSubmit() {
      console.log("submit!");
    },
  },
  created() {
    this.show();
  },
};
</script>

<style>
</style>
